package dao;

import javax.swing.JOptionPane;

public class GenericDAO extends Conection {

    public void persist(Object object) {
        try {
            this.OpenConection();
            em.persist(object);
            em.getTransaction().commit();
            JOptionPane.showMessageDialog(null, "Salvo com sucesso !");
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Erro ao persistir - "+e.getMessage());
            em.getTransaction().rollback();
        } finally {
            this.CloseConection();
        }
    }
    
    public void update(Object object) {
        try {
            this.OpenConection();
            em.merge(object);
            em.getTransaction().commit();
            JOptionPane.showMessageDialog(null, "Alterado com sucesso !");
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Erro ao alterar - "+e.toString());
            em.getTransaction().rollback();
            System.out.println(e.getStackTrace());
            
        } finally {
            this.CloseConection();
        }
    }

}//CLASS
